package com.aiju.cash.ui.setting;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiju.base.activity.BaseTitleActivity;
import com.aiju.cash.R;
import com.aiju.cash.util.ImageDialogUtil;
import com.aiju.common.ImageLoader;
import com.aiju.utils.T;
import com.uuzuche.lib_zxing.activity.CodeUtils;

/**
 * @author: 佐为
 * @date: 2016-12-19 15:47
 * @version: V1.0
 * @Description: 店铺二维码
 */
public class StoreCodeActivity extends BaseTitleActivity {

    private ImageView codeImageView;
    private TextView storeNameTextView;
    private ImageView storeImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_store_code);
        setCenterTitle("店铺二维码");

        codeImageView = (ImageView) findViewById(R.id.iv_store_qr_code);
        storeNameTextView = (TextView) findViewById(R.id.tv_store_name);
        storeNameTextView.setText(getIntent().getStringExtra("name"));
        storeImageView = (ImageView) findViewById(R.id.iv_store_qr);

        if (!TextUtils.isEmpty(mUser.getShopImageUrl())) {
            ImageLoader.loadImage(storeImageView, mUser.getShopImageUrl());
        }

        StringBuilder sb = new StringBuilder("https://trade.ecbao.cn" + "/code/showCode?storeId=");
        sb.append(mUser.getShop().getStoreId());
        sb.append("&shopName=");
        sb.append(mUser.getShop().getShopName());

        Bitmap mBitmap = CodeUtils.createImage(sb.toString(), 400, 400, BitmapFactory.decodeResource(getResources(), R.mipmap.icon_launcher));
        codeImageView.setImageBitmap(mBitmap);
        /*int type = getIntent().getIntExtra("type", 0);
        if (type==1){
           findViewById(R.id.btn_store_code_save).setVisibility(View.GONE);
        }*/

/*        if (!mUser.getShop().isWx()) {
            findViewById(R.id.iv_code_wechat).setVisibility(View.GONE);
        }

        if (!mUser.getShop().isAlipay()) {
            findViewById(R.id.iv_code_zhifu).setVisibility(View.GONE);
        }

        if (!mUser.getShop().isAlipay() && !mUser.getShop().isWx()) {
            findViewById(R.id.iv_code_wechat).setVisibility(View.VISIBLE);
            findViewById(R.id.iv_code_zhifu).setVisibility(View.VISIBLE);
        }*/

        findViewById(R.id.btn_store_code_save).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!mUser.getShop().isWx() && !mUser.getShop().isAlipay()) {
                    T.ToastShort("您尚未签约任何三方支付，顾客将无法通过扫描二维码进行支付，请联系客服");
                    return;
                }
                ImageDialogUtil.saveImageToGallery(StoreCodeActivity.this, ImageDialogUtil.saveCode(findViewById(R.id.ly_store_save_pic)));
                T.ToastShort("图片已保存到本地 Aiiju/QRCode/");
            }
        });
    }


}
